//
//  UINavigationController+LSF.swift
//  hoonpay
//
//  Created by 李胜锋 on 2017/8/23.
//  Copyright © 2017年 lishengfeng. All rights reserved.
//

import Foundation
import UIKit

extension UINavigationController {
    
    ///动画方向
    func lsf_animate(type:String, subType:String) {
        let animation = CATransition.init()
        animation.duration = 0.3
        animation.type = type
        animation.subtype = subType
        animation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionDefault)
        self.view.layer.add(animation, forKey: nil)
    }
    
    
    
    func lsf_pushController_moveIn_FromTop(_ viewController: UIViewController) {
        self.lsf_animate(type: kCATransitionMoveIn, subType: kCATransitionFromTop)
        self.pushViewController(viewController, animated: false)
    }
    
    func lsf_popController_reveal_fromeBottom() {
        
        self.lsf_animate(type: kCATransitionReveal, subType: kCATransitionFromBottom)
        self.popViewController(animated: false)
    }
    
    
    ///获取导航Bar的背景View
    func lsf_navigationBarBackgroundView() -> UIView? {
        guard let backView = navigationBar.value(forKey: "backgroundView") as? UIView else {
            return nil
        }
        return backView
    }
    
    func lsf_getNaviBarBackViewFrame() -> CGRect {
        guard let backView = lsf_navigationBarBackgroundView() else {
            return CGRect.zero
        }
        let rect = backView.superview?.convert(backView.frame, to: self.view)
        return rect ?? CGRect.zero
    }
}
